/**    
 * @Description: 博客园地址：https://www.cnblogs.com/zumengjie/      
 * @author: 顶风少年   
 * @date: 2021年4月5日 下午6:37:20
 */

package datang.dtdb.mapping;

import java.util.List;

import datang.dtdb.session.Configuration;

/**
 * 一个完整的CRUD标签
 */
public class MappedStatement {
	/**
	 * statementId
	 */
	private String id;

	/**
	 * 类型是statement或prepared
	 */
	private StatementType statementType;

	/**
	 * 存储Sql集合的SqlSource
	 */
	private SqlSource sqlSource;

	/**
	 * 返回值
	 */
	private List<ResultMap> resultMaps;

	private Configuration configuration;

	private MappedStatement() {
	}

	public static class Build {
		MappedStatement mappedStatement = new MappedStatement();

		public Build(Configuration configuration) {
			mappedStatement.configuration = configuration;
		}

		public Build id(String id) {
			mappedStatement.id = id;
			return this;
		}

		public Build statementType(StatementType statementType) {
			mappedStatement.statementType = statementType;
			return this;
		}

		public Build sqlSource(SqlSource sqlSource) {
			mappedStatement.sqlSource = sqlSource;
			return this;
		}

		public Build resultMaps(List<ResultMap> resultMaps) {
			mappedStatement.resultMaps = resultMaps;
			return this;
		}

		public MappedStatement build() {
			return mappedStatement;
		}
	}

	/**
	 * 获取statementId
	 */
	public String getId() {
		return id;
	}

	/**
	 * 获取statementType
	 */
	public StatementType getStatementType() {
		return statementType;
	}

	/**
	 * 获取sqlSource
	 */
	public SqlSource getSqlSource() {
		return sqlSource;
	}

	/**
	 * 从SqlSource中获取boundSql
	 */
	public BoundSql getBoundSql(Object parameterObject) {
		return sqlSource.getBoundSql(parameterObject);
	}

	/**
	 * 获取返回值
	 */
	public List<ResultMap> getresultMaps() {
		return resultMaps;
	}
	
	/**
	 * 获取configuration
	 * */
	public Configuration getConfiguration() {
		return configuration;
	}

}
